package com.nf.health.app.widget.custom_chatrow;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMTextMessageBody;
import com.hyphenate.easeui.widget.chatrow.EaseChatRow;
import com.nf.health.app.R;
import com.nf.health.app.activity.manage_health.PreventionChronicActivity;
import com.nf.health.app.utils.ActivityUtils;

import org.json.JSONException;
import org.json.JSONObject;


/**
 * Created by 恩福 on 2016/10/10.
 * 系统消息 去报名 Item
 * @auther changpeng
 * @email obj_cp@126.com
 */

public class EaseChatRowSystemBMCard extends EaseChatRow {


    private TextView contentView;
    private TextView tv_qubaoming;

    public EaseChatRowSystemBMCard(Context context, EMMessage message, int position, BaseAdapter adapter,int state) {
        super(context, message, position, adapter,state);
    }

    @Override
    protected void onInflatView() {
        if(message.direct() == EMMessage.Direct.RECEIVE){
            inflater.inflate(R.layout.ease_row_received_message,this);
        }
    }

    @Override
    protected void onFindViewById() {
        contentView = (TextView) findViewById(com.hyphenate.easeui.R.id.tv_chatcontent);
        tv_qubaoming = (TextView) findViewById(com.hyphenate.easeui.R.id.tv_qubaoming);
    }

    @Override
    protected void onUpdateView() {
        adapter.notifyDataSetChanged();
    }

    @Override
    protected void onSetUpView() {
        EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
        try {
            JSONObject object = new JSONObject("{"+txtBody.getMessage()+"}");
            String content = (String) object.get("content");
            tv_qubaoming.setVisibility(View.VISIBLE);
            contentView.setText(content);
            tv_qubaoming.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {


                    if(!TextUtils.isEmpty(state+"")){

                        if(state == 2){
                            Toast.makeText(context,"您已报名，感谢您的参与~",Toast.LENGTH_SHORT).show();
                        }else{
                            ActivityUtils.showActivity(context,PreventionChronicActivity.class);
                        }
                    }
                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onBubbleClick() {
//
//        ActivityUtils.showActivity(activity, HealthyCurrencyActivity.class);
//        activity.finish();
//        String[] str = tvSubTitle.getText().toString().trim().split("：");
//        CopyDialog dialog = new CopyDialog(context,str[1].trim());
//        dialog.show();
    }

}
